package com.itany.corejava.code07_面向对象.bms;

/**
 * @author 石小俊
 * 2024年07月17日 13:33
 */
public class LoanCreditAccount extends CreditAccount implements Loanable {

    // 贷款金额
    private double loanAmount;

    public double getLoanAmount() {
        return loanAmount;
    }

    public void setLoanAmount(double loanAmount) {
        this.loanAmount = loanAmount;
    }

    @Override
    public void providerLoan(double money) {
        loanAmount += money;
    }

    @Override
    public boolean payLoan(double money) {
        // 对于贷款的信用账户,还款金额不能超出账户余额与信用额度之和
        if (getBalance() + getLimit() >= money) {
            setBalance(getBalance() - money);
            loanAmount -= money;
            return true;
        }
        return false;
    }

    @Override
    public double query() {
        return this.loanAmount;
    }
}
